#include "mxml.h"
#include <stdlib.h>
#include <stdio.h>


int main (int argc , char **argv)
{
/**
 * 创建XML例子 
*/
#if 0
mxml_node_t  *xml;
mxml_node_t  *data;
mxml_node_t  *node;
mxml_node_t  *group;
FILE *fp;

    xml = mxmlNewXML("1.0");
                data = mxmlNewElement(xml,"data");

                            node =mxmlNewElement(data,"node");
                            mxmlNewText(node,1,"val1");
                            node =mxmlNewElement(data,"node");
                            mxmlNewText(node,1,"val2");
                            node =mxmlNewElement(data,"node");
                            mxmlNewText(node,1,"val3");

                            group = mxmlNewElement(data,"group");
                                        node = mxmlNewElement(group,"node");
                                        mxmlNewText(node,0,"val4");
                                        node = mxmlNewElement(group,"node");
                                        mxmlNewText(node,0,"val5");
                                        node = mxmlNewElement(group,"node");
                                        mxmlNewText(node,0,"val6");
 
                            node = mxmlNewElement(data,"node");
                            mxmlNewText(node,0,"val7");
                            node = mxmlNewElement(data,"node");
                            mxmlNewText(node,0,"val8");     
                            node = mxmlNewElement(data,"node");
                            mxmlNewText(node,0,"val9"); 
        fp = fopen("test.xml","w");
        mxmlSaveFile(xml,fp,MXML_NO_CALLBACK);
        fclose(fp);
        mxmlDelete(xml);
#endif
/**
 * 实际创建GATEWAY.XML文件
*/
#if 1
        mxml_node_t     *xml;
        mxml_node_t     *Gateway;
        mxml_node_t     *GatewayID;
        mxml_node_t     *GatewayIP;
        mxml_node_t     *DevNum;
        mxml_node_t     *TransNum;
        mxml_node_t     *TMSN;
        mxml_node_t     *PollTime;
        mxml_node_t     *PlatNam;
        mxml_node_t     *ManagerIP;
        mxml_node_t     *Port;
        FILE                            *fp;
        xml = mxmlNewXML("1.0");
                    Gateway = mxmlNewElement(xml,"Gateway");
                                GatewayID = mxmlNewElement(Gateway,"GatewayID");
                                mxmlNewText(GatewayID,0,"B-24000-190830-70001");
                                GatewayIP = mxmlNewElement(Gateway,"GatewayIP");
                                mxmlNewText(GatewayIP,0,"192.168.99.99");
                                DevNum = mxmlNewElement(Gateway,"DevNum");
                                mxmlNewText(DevNum,0,"1");
                                TransNum = mxmlNewElement(Gateway,"TransNum");
                                mxmlNewText(TransNum,0,"1");
                                TMSN = mxmlNewElement(Gateway,"TMSN");
                                mxmlNewText(TMSN,0,"1");
                                PollTime = mxmlNewElement(Gateway,"PollTime");
                                mxmlNewText(PollTime,0,"1000");
                                PlatNam = mxmlNewElement(Gateway,"PlatNam");
                                mxmlNewText(PlatNam,0,"DM");
                                ManagerIP = mxmlNewElement(Gateway,"ManagerIP");
                                mxmlNewText(ManagerIP,0,"mqtt.mkmsmart.com");
                                Port = mxmlNewElement(Gateway,"Port");
                                /**
                                 * 经过测试 使用 文本格式生产的1883和使用数字生成的1883并没有什么区别
                                */
                                //mxmlNewText(Port,0,"1883");
                                mxmlNewInteger(Port,1883);                            
/**
 * 保存XML文件
*/
        //fp = fopen("my_Gateway.xml","w");
        fp = fopen("you_Gateway.xml","w");
        mxmlSaveFile(xml,fp,MXML_NO_CALLBACK);
        fclose(fp);
        mxmlDelete(xml);
#endif
}